package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.ResCategory;
import com.ruoyi.system.service.IResCategoryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ResInfo;
import com.ruoyi.system.service.IResInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 餐馆Controller
 * 
 * @author ruoyi
 * @date 2025-05-29
 */
@RestController
@RequestMapping("/system/resinfo")
public class ResInfoController extends BaseController
{
    @Autowired
    private IResInfoService resInfoService;

    @Autowired
    private IResCategoryService resCategoryService;

    /**
     * 查询餐馆列表
     */
    @PreAuthorize("@ss.hasPermi('system:resinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResInfo resInfo)
    {
        startPage();
        List<ResInfo> list = resInfoService.selectResInfoList(resInfo);
        return getDataTable(list);
    }

    /**
     * 根据餐饮管理员id查询餐馆列表
     */
    @PreAuthorize("@ss.hasPermi('system:resinfo:list')")
    @GetMapping("/list1")
    public TableDataInfo list1(ResCategory category)
    {
        startPage();
        List<ResInfo> list = resInfoService.selectResInfoListByCategory(category);
        return getDataTable(list);
    }

    /**
     * 根据分类名称查询餐馆列表
     */
    @PreAuthorize("@ss.hasPermi('system:resinfo:list')")
    @GetMapping("/listByCategoryName")
    public TableDataInfo listByCategoryName(@RequestParam("categoryName") String categoryName) {
        startPage();
        ResCategory category = resCategoryService.selectResCategoryByCategoryName(categoryName);
        ResInfo resInfo = new ResInfo();
        if (category != null) {
            resInfo.setCategoryId(category.getCategoryId());
        }
        List<ResInfo> list = resInfoService.selectResInfoList(resInfo);
        return getDataTable(list);
    }

    /**
     * 导出餐馆列表
     */
    @PreAuthorize("@ss.hasPermi('system:resinfo:export')")
    @Log(title = "餐馆", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResInfo resInfo)
    {
        List<ResInfo> list = resInfoService.selectResInfoList(resInfo);
        ExcelUtil<ResInfo> util = new ExcelUtil<ResInfo>(ResInfo.class);
        util.exportExcel(response, list, "餐馆数据");
    }

    /**
     * 获取餐馆详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:resinfo:query')")
    @GetMapping(value = "/{resId}")
    public AjaxResult getInfo(@PathVariable("resId") Long resId)
    {
        return success(resInfoService.selectResInfoByResId(resId));
    }

    /**
     * 新增餐馆
     */
    @PreAuthorize("@ss.hasPermi('system:resinfo:add')")
    @Log(title = "餐馆", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResInfo resInfo)
    {
        return toAjax(resInfoService.insertResInfo(resInfo));
    }

    /**
     * 修改餐馆
     */
    @PreAuthorize("@ss.hasPermi('system:resinfo:edit')")
    @Log(title = "餐馆", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResInfo resInfo)
    {
        System.out.println(resInfo);
        return toAjax(resInfoService.updateResInfo(resInfo));
    }

    /**
     * 删除餐馆
     */
    @PreAuthorize("@ss.hasPermi('system:resinfo:remove')")
    @Log(title = "餐馆", businessType = BusinessType.DELETE)
	@DeleteMapping("/{resIds}")
    public AjaxResult remove(@PathVariable Long[] resIds)
    {
        return toAjax(resInfoService.deleteResInfoByResIds(resIds));
    }
    /**
     * 条件查询餐馆
     */
    @GetMapping("/selectResInfoByCategory")
    public List<ResInfo> selectResInfoByCategory(@RequestParam("categoryId") Integer categoryId, @RequestParam("type") Integer type) {
        return resInfoService.selectResInfoListByCategory(categoryId, type);
    }

}
